package com.paradogs.gs.modules.world.base.unit;

import com.paradogs.common._cfg.Cfg;
import com.paradogs.gs.modules.WorldObject;
import com.paradogs.gs.modules.WorldSyncData;
import lombok.Getter;

/**
 * @author: yumi
 * @date: 2025/4/21  16:08
 * @Description: TODO
 */
public class WorldNPC extends WorldObject {

    @Getter
    private Cfg.WorldUnit template;
    private Runnable revertWorldCount;

    public WorldNPC(Cfg.WorldUnit template) { this(template, null); }
    public WorldNPC(Cfg.WorldUnit template, Runnable revertWorldCount) {
        this.template = template;
        load(
                -Long.valueOf(template.id()),
                template.world(),
                template.x(),
                template.y(),
                template.hp() != null ? template.hp() : 1,
                template.hp() != null ? template.hp() : 1,
                1,
                1,
                UnitType.NPC
        );
    }

    @Override
    public WorldSyncData toSyncData() {
        return new WorldSyncData(
                getId(),
                template.name(),
                UnitType.NPC,
                template.level(),
                getHp(),
                getMaxHp(),
                getMp(),
                getMaxMp(),
                "描述1",
                "描述2"
        );
    }

    @Override
    public void onDead(WorldObject killer) {
        if (revertWorldCount != null) {
            revertWorldCount.run();
        }
    }

}
